<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once 'Mail.php';

class Mail{
	private $to;
	private $from;
	private $subject = "Testando envio autenticado pelo Google";
	private $body = "Teste efetuado com sucesso!";
	private $host = "http://smtp.gmail.com";
	private $port = 25;
	private $username;
	private $password;

	public function getTo(){
		return $this->to;
	}
	public function setTo($t){
		$this->to = $t;
	}
	public function getFrom(){
		return $this->from;
	}
	public function setFrom($f){
		$this->from = $f;
	}
	public function getSubject(){
		return $this->subject;
	}
	public function setSubject($s){
		$this->subject = $s;
	}
	public function getBody(){
		return $this->body;
	}
	public function setBody($b){
		$this->body = $b;
	}
	public function getHost(){
		return $this->host;
	}
	public function setHost($h){
		$this->host = $h;
	}
	public function getPort(){
		return $this->port;
	}
	public function setPort($p){
		$this->port = $p;
	}
	public function getUsername(){
		return $this->username;
	}
	public function setUsername($un){
		$this->username = $un;
	}
	public function getPassword(){
		return $this->password;
	}
	public function setPassword($p){
		$this->password = $p;
	}

	public function send($debug = false){
            echo "entrou";
		$headers = array ('From' => $this->getFrom(),
                            'To' => $this->getTo(),
                            'Subject' => $this->getSubject());

		$smtp = Mail::factory("smtp", array ('host' => $this->getHost(),
                                          'port' => $this->getPort(), // SMTPS(para mais detalhes ver /etc/services
                                          'auth' => true,
                                          'debug' => $debug,
                                          'username' => $this->getUsername(),
                                          'password' => $this->getPassword())
		);
		$rc = $smtp->send($this->getTo(), $headers, $this->getBody());
		if(PEAR::isError($rc)){
			echo("<h1>Error " . $rc->getMessage(). "</h1>");
		} else {
			echo("Email enviado com sucesso!!");
		}
	}
}
?>
